import java.util.*;
import java.io.*;
/**
 * @author Garima Pandey
 */
public class Repeated_Words {
        static String inputFile;
        static String[] formattedLineString;
        static int[]index;
        static String lineString = "";

        public static void main(String[] args) {
                File textFile;
                FileReader textReader;
                LineNumberReader lineNumber;
                Map<String, Integer> wordMap;
                String wordString;
                
                try{
                        textFile = new File("/Users/prathup/Desktop/input.txt");
                        textReader = new FileReader(textFile);
                        lineNumber = new LineNumberReader(textReader);
                        //traverse the lines in the textFile
                        while((lineString  = lineNumber.readLine()) != null){
                                //format the lines so we can do something with it
                formattedLineString = lineString.replaceAll("[\\n]", " ").replaceAll("[!.,?!:;/()]","").split(" ");
                //create the new map for storing the words
                wordMap = new LinkedHashMap<String,Integer>();
                for(int i =0; i< formattedLineString.length; i+=1){
                    String tempString = formattedLineString[i];
                    //check if map has the word, if it doesn't, add it, or increase the count
                    if(wordMap.get(tempString) == null){
                        wordMap.put(tempString, 1);
                    }else{
                        wordMap.put(tempString, wordMap.get(tempString) +1);
                    }
                }
                Set<String> words = wordMap.keySet();
                for(String word:words){
                        //print if the word is repeated
                        if(wordMap.get(word) > 1){
                                wordString = word;
                                for(int i = 0; i<wordMap.get(word)-1; i +=1){
                                        wordString += " " + word;
                                
                                
                                System.out.println("Repeated word on line " + lineNumber.getLineNumber() + " : " + wordString);
                                }
                        }
                }
                        }
                        textReader.close();
                        lineNumber.close();
                }catch (IOException e){
                        System.out.println("Cannot open selected file");
                }
        }

}